<?php get_instance()->view('common/header');?>
<style>
	        input::-webkit-input-placeholder{
            color:#333;
        }
        input::-moz-placeholder{   /* Mozilla Firefox 19+ */
            color:#333;
        }
        input:-moz-placeholder{    /* Mozilla Firefox 4 to 18 */
            color:#333;
        }
        input:-ms-input-placeholder{  /* Internet Explorer 10-11 */ 
            color:#333;
        }
</style>
<body class="bag3">
<div class="content">
    <form action="<?php echo getUrl('find/saveFind')?>" id="save-form" method="post">
        <textarea class="weui-textarea p3p f09" placeholder="说点什么吧..." rows="5" name="content" ><?php echo !$add ? $info['content'] : ''?></textarea>
        <div class="weui-gallery" id="gallery">
            <span class="weui-gallery__img" id="galleryImg"></span>
            <div class="weui-gallery__opr">
                <a href="javascript:" class="weui-gallery__del">
                    <i class="weui-icon-delete weui-icon_gallery-delete"></i>
                </a>
            </div>
        </div>
        <div class="weui-cells weui-cells_form mt0">
            <div class="weui-cell P0">
                <div class="weui-cell__bd">
                    <div class="weui-uploader">
                        <div class="weui-uploader__hd">
                            <p class="weui-uploader__title f08 cor9">您最多可以上传4张图片</p>
                            <div class="weui-uploader__info f08"><span class="f10 weui-uploader_number">
                                    <?php echo !$add && !empty($info['pic']) ? count($info['pic']) : 0?>
                                </span>/4</div>
                        </div>
                        <div class="weui-uploader__bd">
                            <ul class="weui-uploader__files" id="uploaderFiles">
                                <?php if (!$add && !empty($info['pic'])): foreach ($info['pic'] as $k => $v):?>
                                <li class="weui-uploader__file" style="background-image:url(<?php echo $v?>)">
                                    <input type="hidden" name="img[]" value="<?php echo $v?>">
                                </li>
                                <?php endforeach; endif;?>
    <!--                            <li class="weui-uploader__file" style="background-image:url(img/jpg/pic1.jpg)"></li>-->
    <!--                            <li class="weui-uploader__file" style="background-image:url(img/jpg/pic1.jpg)"></li>-->
    <!--                            <li class="weui-uploader__file weui-uploader__file_status" style="background-image:url(./images/pic_160.png)">-->
    <!--                                <div class="weui-uploader__file-content">-->
    <!--                                    <i class="weui-icon-warn"></i>-->
    <!--                                </div>-->
    <!--                            </li>-->
    <!--                            <li class="weui-uploader__file weui-uploader__file_status" style="background-image:url(./images/pic_160.png)">-->
    <!---->
    <!--                            </li>-->
                            </ul>
                            <div class="weui-uploader__input-box jdjz">
                                <img src="<?php echo $this->staticUrl?>img/png/pic104.png">
                                <input id="uploaderInput" class="weui-uploader__input chooseImage" type="file" accept="image/*" multiple/>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <script type="text/javascript">
                $(function () {
                    <?php $number = !$add && !empty($info['pic']) ? 4 - count($info['pic']) : 4?>
                    weUiImg({
                        name:'images[]',
                        imagesNumber:4,
                        changeImagesNumber:<?php echo $number?>
                    });
                })
            </script>
        </div>
        <div class="weui-cells mt7">
            <div class="weui-cell weui-cell_access">
                <div class="weui-cell__bd vCenter hengleft">
                    <span class="f085">标题</span>
                    <input class="listleftinput b0" type="text" placeholder="请填写标题" name="title" value="<?php echo !$add ? $info['title'] : ''?>">
                </div>
            </div>
            <div class="weui-cell weui-cell_access">
                <div class="weui-cell__bd">
                    <span class="hengleft vCenter f085">类型</span>
                </div>
                <div class="weui-cell__ft f08">
                    <select class="weui-select category" name="category_id"  style="direction: rtl;">
                        <?php foreach ($category as $k => $v):?>
                            <option attr = "<?php echo isset($v['attr_cate_id'])?$v['attr_cate_id']:0; ?>" <?php if (!$add && $info['category_id'] == $v['id']):?> selected="selected" style="direction: rtl;" <?php endif;?> value="<?php echo $v['id']?>"><?php echo $v['name']?></option>
                        <?php endforeach;?>
                    </select>
                </div>
                <script type="text/javascript">
                    $(function () {
                        $(".category").change(function () {
//                            var vl = $(".category").val();
                            var  vl = $(this).find("option:selected").attr("attr")
                            blockUI.show();
                            $.ajax('<?php echo getUrl('find/appAttribute');?>', {
                                type:'post',
                                data:{category_id:vl},
                                dataType:'json',
                                error:function(){
                                    blockUI.hide();
                                    show_message({status:0, message:'请求超时'});
                                },
                                timeout:60000,
                                success:function(e,textStatus,jqXHR){
                                    blockUI.hide();
                                    $(".attribute").remove();
                                    var html = '';
                                    var index = 0;
                                    $.each(e.data, function (key, obj) {
                                        html += '<div class="weui-cell weui-cell_access attribute">' +
                                            '<div class="weui-cell__bd">' +
                                            '<span class="hengleft vCenter f085">'+ obj.attr_name +'</span></div>' +
                                            '<input type="hidden" value="'+obj.id+'" name="attribute['+index+'][attr_id]"/>';
                                        var type = obj.attr_input_type;
                                        if (type == 1){ // 文本框输入(纯数字)
                                            html += '<div class="">' +
                                                        '<input class="listleftinput listrightinput b0" type="number" name="attribute['+index+'][attr_value]">' +
                                                    '</div></div>';
                                        }else if (type == 2){ // 文本框输入(文本)
                                            html += '<div class="">' +
                                                    '<input class="listleftinput listrightinput b0" type="text" name="attribute['+index+'][attr_value]">' +
                                                '</div></div>';
                                        }else if(type == 3){  // 选择输入
                                            html += '<div class="weui-cell__ft">' +
                                                '<select class="weui-select category" name="attribute['+index+'][attr_value]">';
                                            for(var i=0; i < obj.attr_values.length; i++){
                                                var vs = obj.attr_values[i];
                                                html += '<option value="'+vs+'">'+vs+'</option>';
                                            }
                                            html += '</select></div></div>';
                                        }else if(type == 4){  // 多行文本输入
                                            html += '<div class="">' +
                                                '<textarea class="b0" name="attribute['+index+'][attr_value]"></textarea>' +
                                                '</div></div>';
                                        }else if(type == 5){  // 城市类 - 暂不考虑

                                        }else{
                                            return false;
                                        }
                                        $(".after_attribute").after(html);
                                    });
//                                    $(".attribute").html(html);
                                }
                            });
                        })
                    })
                </script>
            </div>
<!--            <div class="attribute">-->
                <?php if (!$add && !empty($info['attr'])): foreach ($info['attr'] as $k => $v):?>
                <!--单选框-->
                <div class="weui-cell weui-cell_access attribute">
                    <div class="weui-cell__bd">
                        <span class="hengleft vCenter f085"><?php echo $v['attr_name']?></span>
                    </div>
                    <input type="hidden" value="<?php echo $v['id']?>" name="attribute[<?php echo $k?>][attr_id]"/>
                    <?php if ($v['attr_input_type'] == 1): // 文本框输入(纯数字) ?>
                        <div class="">
                            <input class="listleftinput listrightinput b0" type="tel" value="<?php echo $v['attr_value']?>" name="attribute[<?php echo $k?>][attr_value]">
                        </div>
                    <?php elseif ($v['attr_input_type'] == 2): // 文本框输入(文本) ?>
                        <div class="">
                            <input class="listleftinput listrightinput b0" type="text"  value="<?php echo $v['attr_value']?>" name="attribute[<?php echo $k?>][attr_value]">
                        </div>
                    <?php elseif ($v['attr_input_type'] == 3): // 选择输入 ?>
                        <div class="weui-cell__ft">
                            <select class="weui-select category" name="attribute[<?php echo $k?>][attr_value]">
                                <?php foreach ($v['attr_values'] as $kk => $vv):?>
                                    <option <?php if ($v['attr_value'] == $vv):?> selected <?php endif;?> value="<?php echo $vv?>"><?php echo $vv?></option>
                                <?php endforeach;?>
                            </select>
                        </div>
                    <?php elseif ($v['attr_input_type'] == 4): // 多行文本输入 ?>
                        <div class="">
                            <textarea class="b0" name="attribute[<?php echo $k?>][attr_value]"><?php echo $v['attr_value']?></textarea>
                        </div>
                    <?php elseif ($v['attr_input_type'] == 5): // 城市类 - 暂不考虑 ?>

                    <?php endif;?>
                </div>
                <?php endforeach; endif;?>
                <!--多选框-->
                <!--<div class="weui-cell weui-cell_access">
                    <div class="weui-cell__bd">
                        <span class="hengleft vCenter f085">价格</span>
                    </div>
                    <div class="">
                        <textarea class="b0"></textarea>
                    </div>
                </div>-->
                <!--下拉框-->
                <!--<div class="weui-cell weui-cell_access">
                    <div class="weui-cell__bd">
                        <span class="hengleft vCenter f085">新旧</span>
                    </div>
                    <div class="weui-cell__ft f08 fenlbtn">请选择新旧</div>
                </div>-->
<!--            </div>-->
            <div class="after_attribute"></div>
            <!--城市联动-->
            <div class="weui-cell weui-cell_access ">
                <div class="weui-cell__bd">
                    <span class="hengleft vCenter f085">城市</span>
                </div>
                <div class="weui-cell__ft f08">
                    <input type="text" class="showDouble b0 tr f10 cor3" data-type="county_name" placeholder="请选择城市区域" value="<?php echo !$add ? $info['county_name'] : ''?>" readonly>
                    <input type="hidden" name="province" value="<?php echo !$add ? $info['province'] : ''?>">
                    <input type="hidden" name="city" value="<?php echo !$add ? $info['city'] : ''?>">
                    <input type="hidden" name="county" value="<?php echo !$add ? $info['county'] : ''?>">
                    <input type="hidden" name="county_name" value="<?php echo !$add ? $info['county_name'] : ''?>">
                </div>
                <script type="text/javascript">
                    $(function () {
                        //2级联动
                        var data = JSON.parse('<?php echo $location?>');
                        var _picker, defaultValue;
                        <?php if (!$add):?>
                        defaultValue = ['<?php echo $info["province"]?>','<?php echo $info["city"]?>','<?php echo $info["county"]?>'];
                        <?php else:?>
                        defaultValue = ['32','394','3330'];
                        <?php endif;?>
                        $('.showDouble').on('click', function () {
                            var name = $(this).attr('data-type');
                            _picker = $(this);
                            weui.picker(data, {
                                id:name,
                                defaultValue:defaultValue,
                                onChange: function (result) {
                                },
                                onConfirm: function (result) {
                                    var id = result[0]+','+result[1]+','+result[2];
                                    getAjax(id);
                                    $('[name="province"]').val(result[0]);
                                    $('[name="city"]').val(result[1]);
                                    $('[name="county"]').val(result[2]);
                                }
                            });
                        });

                        function getAjax(id) {
                            blockUI.show();
                            $.ajax('<?php echo getUrl('common/getAjaxAddress');?>', {
                                type:'post',
                                data:{address_id:id},
                                error:function(){
                                    blockUI.hide();
                                    show_message({status:0, message:'请求超时'});
                                },
                                timeout:60000,
                                success:function(e,textStatus,jqXHR){
                                    blockUI.hide();
                                    _picker.val(e);
                                    $('[name="county_name"]').val(e);
                                }
                            });
                        }
                    })
                </script>
            </div>
            <!--详情地址-->
            <div class="weui-cell weui-cell_access address">
                <div class="weui-cell__bd">
                    <span class="hengleft vCenter f085">位置</span>
                </div>
                <div class="weui-cell__ft f08 "><?php echo !$add ? $info['address_name'] : ''?></div>

                <script type="text/javascript">
                    $(function () {
                        // 显示地图
                        $(".address").click(function () {
                            $(".map_div").show();
                            $(".content").hide();
                        });
                    })
                </script>
            </div>
            <input type="hidden" value="<?php echo !$add ? $info['address_name'] : ''?>" name="address">
            <input type="hidden" value="<?php echo !$add ? $info['latitude'] : ''?>" name="latitude">
            <input type="hidden" value="<?php echo !$add ? $info['longitude'] : ''?>" name="longitude">
        </div>
        <div class="bag3">
            <p class="f09 p3p">信息核对</p>
        </div>
        <div class="pb50">
            <div class="weui-cells mt0">
                <div class="weui-cell weui-cell_access">
                    <div class="weui-cell__bd vCenter hengleft">
                        <span class="f085">姓名：</span>
                        <input class="listleftinput b0" type="text" placeholder="请填写姓名" value="<?php echo !$add ? $info['nickname'] : $user['userName']?>" name="nickname">
                    </div>
                </div>
                <div class="weui-cell weui-cell_access">
                    <div class="weui-cell__bd vCenter hengleft">
                        <span class="f085">手机：</span>
                        <input class="listleftinput b0" type="text" placeholder="请填写手机号" value="<?php echo !$add ? $info['mobile'] : $user['userMobile']?>" name="mobile">
                    </div>
                </div>
            </div>
        </div>
        <div class="shopcarbox bag1">
            <input type="hidden" value="<?php echo !$add ? $info['id'] : 0?>" name="id">
            <button class="dk p5_0 bag2 wp100 cor1 tc f10">立即发布</button>
        </div>
    </form>
    <script type="text/javascript">
        $(function () {
            $.e_validate.init('#save-form',{saveMessage:'保存中...'});
        })
    </script>
</div>
<?php get_instance()->view('common/map');?>
</body>
<script src="<?php echo $this->staticUrl?>js/base.js"></script>
</html>